package com.skycong.hello77.activity.togglebutton;

import android.app.Activity;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.ToggleButton;
import com.skycong.hello77.R;

/**
 * @author ruanmingcong
 * @date 2018/1/7 21:16
 */
public class toggleActivity extends Activity implements CompoundButton.OnCheckedChangeListener {
    private ToggleButton tb;
    private ImageView img;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.toggle_activity);
        /*
        * 初始化控件
        *
        *
        * */
        tb = (ToggleButton) findViewById(R.id.toggle_button);
        img = (ImageView) findViewById(R.id.image_close);
        //设置监听器
        tb.setOnCheckedChangeListener(this);
    }


    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        //三目运算符,buttonView代表被点击的当前toggleButton
        img.setBackgroundResource(isChecked?R.mipmap.dindan_ic:R.mipmap.close_btn);
    }
}
